#include <Duinolab.h>
#include <Wire.h>

void setup() {
  // Initialize the Duinolab
  Duinolab.Init();
  
  pinMode(4, OUTPUT);
  
  // Connect potentiometer 0
  Duinolab.ConnectToArduino(POT_BLACK);
  Duinolab.ConnectToArduino(BUTTON_YELLOW);
}

/* create tone between 300 and 3300 Hz 
For 3300 Hz, need 300 microsecond period.  For 300, need 3300 period.
so, each half = 150 uS + read value * 1.5

*/
void loop() {
  int potvalue = Duinolab.ReadPot(POT_BLACK);
  int delaytime = 150 + potvalue + (potvalue >> 1);
  if(Duinolab.ButtonPressed(BUTTON_YELLOW)) {
    digitalWrite(4, HIGH);
  }
  delayMicroseconds(delaytime);
  digitalWrite(4, LOW);
  delayMicroseconds(delaytime);
}
